﻿function ClientAddNews(GroupNewsId) {
    GroupNewsItemId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;

    Url = Portal.CMS.InputNews.GetAddNewUrl(GroupNewsId, GroupNewsItemId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_self');
}

function ClientStdAddNews(GroupNewsId, GroupNewsItemId) {
    Url = Portal.CMS.InputNews.GetAddNewUrl(GroupNewsId, GroupNewsItemId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientSaveAddNews(GroupNewsId, GroupNewsItemId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    Subject = document.getElementById("txtSubject").value;
    Source = document.getElementById("txtSource").value;

    //var instanceName="ctl04";
    //var oEditor = FCKeditorAPI.GetInstance(instanceName) ;
    //ShortContent= oEditor.GetXHTML( true );
    ShortContent = document.getElementById("txtShortContent").value;

    instanceName = "ctl04";
    oEditor = FCKeditorAPI.GetInstance(instanceName);
    bodyText = oEditor.GetXHTML(true);

    SearchKeyword = document.getElementById("txtSearchKeyword").value;
    ImageUrl = "";
    //ImageUrl = document.getElementById("txtImageUrl").value;
    EntryDate = document.getElementById("txtEntryDate").value;

//    AttactedImage = document.getElementById("chkAttactedImage").checked;
//    AttactedVideo = document.getElementById("chkAttactedVideo").checked;
    AttactedDoc = document.getElementById("chkAttactedDoc").checked;

//    EmObjectVideo = document.getElementById("txtEmObjectVideo").value;
//    EmObjectAudio = document.getElementById("txtEmObjectAudio").value;

    NewsId = Portal.CMS.AddNews.ServerSideAddNews(language, GroupNewsId, GroupNewsItemId, Subject, ImageUrl, ShortContent, bodyText, SearchKeyword, Source, EntryDate, AttactedDoc).value;
    //NewsId = Portal.CMS.AddNews.ServerSideAddNews(language, GroupNewsId, GroupNewsItemId, Subject, ImageUrl, ShortContent, bodyText, SearchKeyword, Source, EntryDate, AttactedDoc, AttactedImage, AttactedVideo, EmObjectVideo, EmObjectAudio).value;
    if (NewsId.indexOf("ERROR") != -1) {
        alert(NewsId);
        return;
    }
    ConfirmUploadImageMsg = Portal.CMS.AddNews.GetConfirmUploadImage().value;
    if (confirm(ConfirmUploadImageMsg) == true) {
        ClientUploadImageUrlFromAddNews(NewsId);
    }
    window.close();
}

function ClientUploadImageUrlFromAddNews(NewsId) {
    Url = Portal.CMS.AddNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientSaveNews(GroupNewsId, NewsId) {
    Subject = document.getElementById("txtSubject").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    if (FCKeditorAPI == null) {
        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
        return;
    }

    //    var instanceName="ctl04";
    //    var oEditor = FCKeditorAPI.GetInstance(instanceName) ;
    //    
    //    if(oEditor==null)
    //    {
    //        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
    //        return;
    //    }
    ShortContent = document.getElementById("txtShortContent").value; //   oEditor.GetXHTML( true );

    instanceName = "ctl04";
    oEditor = FCKeditorAPI.GetInstance(instanceName);
    if (oEditor == null) {
        alert(Portal.CMS.UpdateNews.GetLoadDataMsg().value);
        return;
    }
    bodyText = oEditor.GetXHTML(true);
    SearchKeyword = document.getElementById("txtSearchKeyword").value;
    ImageUrl = document.getElementById("txtImageUrl").value;
    Source = document.getElementById("txtSource").value;
    EntryDate = document.getElementById("txtEntryDate").value;

    AttactedImage = document.getElementById("chkAttactedImage").checked;
    AttactedVideo = document.getElementById("chkAttactedVideo").checked;
    AttactedDoc = document.getElementById("chkAttactedDoc").checked;

    EmObjectVideo = document.getElementById("txtEmObjectVideo").value;
    EmObjectAudio = document.getElementById("txtEmObjectAudio").value;


    value = Portal.CMS.UpdateNews.ServerSideNews(language, NewsId, Subject, ImageUrl, ShortContent, bodyText, SearchKeyword, Source, EntryDate, AttactedDoc, AttactedImage, AttactedVideo, EmObjectVideo, EmObjectAudio).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(value)
    //window.close();
}

function RunFilter(GroupNewsId) {
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    GroupNewsItemId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.InputNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatusIndex, PageIndex).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    document.getElementById("divNewsContent").innerHTML = value;
}

function ClientDeleteNews(GroupNewsId, NewsId) {
    value = Portal.CMS.InputNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.InputNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.InputNews.GetDeleteOkMsg().value);
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    GroupNewsItemId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    value = Portal.CMS.InputNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatusIndex, PageIndex).value;
    document.getElementById("divNewsContent").innerHTML = value;
}





function ClientDeleteSearchNews(GroupNewsId, GroupNewsItemId, NewsId) {
    value = Portal.CMS.InputNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.InputNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.InputNews.GetDeleteOkMsg().value);
    SearchNewsJumpPage();
}


function ShowUpdateNewsForm(GroupNewsId, NewsId) {
    Url = Portal.CMS.InputNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ShowUpdateSearchNewsForm(GroupNewsId, GroupNewsItemId, NewsId) {
    Url = Portal.CMS.InputNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    SearchNewsJumpPage();
}


function ShowUpdateStdAloneNewsForm(GroupNewsId, GroupNewsItemId, NewsId) {
    Url = Portal.CMS.InputNews.GetUpdateNewsUrl(GroupNewsId, NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function DetectHtmlBody(NewsId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue = Portal.CMS.UpdateNews.GetSubject(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("txtSubject").value = retValue;

    //shortcontent
    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    retValue = Portal.CMS.UpdateNews.GetShortContent(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    oEditor.SetHTML(retValue);


    //body
    instanceName = "ctl05";
    oEditor = FCKeditorAPI.GetInstance(instanceName);
    retValue = Portal.CMS.UpdateNews.GetBody(language, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    oEditor.SetHTML(retValue);
}

function PublishingNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function UnPublishingNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function PublishingStdAloneNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function PublishingStdAloneNewsInFocus(NewsId) {
    retValue = Portal.CMS.FocusNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.FocusNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.FocusNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}





function UnPublishingStdAloneNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function UnPublishingStdAloneNewsInFocus(NewsId) {
    retValue = Portal.CMS.FocusNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.FocusNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.FocusNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function PublishingSearchNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSidePublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}


function UnPublishingSearchNews(NewsId) {
    retValue = Portal.CMS.InputNews.CheckAllowPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmUnPublishingNewsMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.InputNews.ServerSideUnPublishingNews(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}



function PermissionStdAloneNews(NewsId) {
    Url = Portal.CMS.InputNews.GetShowFormSetPermission(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');

}


function PermissionNews(NewsId) {
    Url = Portal.CMS.InputNews.GetShowFormSetPermission(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');

}

function ClientUploadImageUrl(NewsId) {
    Url = Portal.CMS.InputNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientUploadImageUrlInFocus(NewsId) {
    Url = Portal.CMS.FocusNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientUploadImageUrlForSearchNews(NewsId) {
    Url = Portal.CMS.InputNews.GetUpdateImageUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function SearchNewsJumpPage() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.InputNews.GetSearchProcessingMsg().value;
    setTimeout("RealSearchNewsJumpPage()", 10);
}

function RealSearchNewsJumpPage() {
    if (document.getElementById("divSelectSearchNewsPage") != null) {
        PageIndex = document.getElementById("divSelectSearchNewsPage").selectedIndex;
    }
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    Keyword = document.getElementById("txtSearchKeyword").value;
    fromDate = document.getElementById("txtFromDate").value;
    toDate = document.getElementById("txtToDate").value;
    belongSiteIndex = document.getElementById("drpSelectSite").selectedIndex;
    belongSite = document.getElementById("drpSelectSite").options[belongSiteIndex].value;
    GroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    Source = document.getElementById("txtSource").value;
    retValue = Portal.CMS.InputNews.GetHtml(belongSite, Keyword, fromDate, toDate, WorkflowStatusIndex, GroupNewsItemId, Source, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divSearchNewsContent").innerHTML = retValue;
}

function SearchNews() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.InputNews.GetSearchProcessingMsg().value;
    setTimeout("RealSearchNewsJumpPage(0)", 10);
}

function FilterFunc() {
    LoadGroupNewsItem();
}

function LoadGroupNewsItem() {
    belongSite = document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    retValue = Portal.CMS.InputNews.ServerSideGetGroupNewsItem(belongSite).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divSelectGroupNewsItem").innerHTML = retValue;
}

function ClientSetShowOnTop(NewsId) {
    retValue = Portal.CMS.InputNews.ServerSideSetShowOnTop(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function ClientSetShowOnTopInFoCus(NewsId) {
    retValue = Portal.CMS.FocusNews.ServerSideSetShowOnTop(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}


function ClientDisShowOnTop(NewsId) {
    retValue = Portal.CMS.InputNews.ServerSideDisShowOnTop(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function ClientDisShowOnTopInFoCus(NewsId) {
    retValue = Portal.CMS.FocusNews.ServerSideDisShowOnTop(NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}



function ClientSyncNews(NewsId) {
    if (confirm(Portal.CMS.InputNews.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.InputNews.GetSyncProcessing().value;
    setTimeout("RealClientSyncNews('" + NewsId + "')", 10);
}

function RealClientSyncNews(NewsId) {
    retValue = Portal.CMS.InputNews.ServerSideSyncToServer(NewsId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
}

function ClientMoveItemNews(belongSite, GroupNewsItemId, NewsId) {
    url = Portal.CMS.InputNews.GetMoveNewsUrl(NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    //window.showModalDialog(url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(url, '_blank');
}



function ClientExecuteMoveNews(NewsId) {
    if (confirm(Portal.CMS.MoveNews.GetConfirmMoveMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.MoveNews.GetProcessingMove().value;
    setTimeout("RealClientExecuteMoveNews('" + NewsId + "')", 10);
}

function RealClientExecuteMoveNews(NewsId) {

    MoveToGroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    retValue = Portal.CMS.MoveNews.ServerSideMoveNews(NewsId, MoveToGroupNewsItemId).value;
    document.getElementById("divProcessing").innerHTML = "";
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}

//function ClientUploadDocumentContent(belongSite, NewsId) {
//    url = Portal.CMS.InputNews.GetUploadDocumentContentUrl(belongSite,NewsId).value;
//    if (url.indexOf("ERROR") != -1) {
//        alert(url);
//        return;
//    }
//    window.open(url, '_blank');
//}

function ClientUploadDocumentContent(belongSite, NewsId) {
    url = Portal.CMS.UpdateAttachmentsNews.GetUploadDocumentContentUrl(belongSite, NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    window.open(url, '_blank');
}

function ShowNewsHistory(NewsId) {
    Url = Portal.CMS.InputNews.GetLogUrl(NewsId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientDetectGroupNewsItem() {
    GroupNewsId = document.getElementById("drpSelectGroupNews").options[document.getElementById("drpSelectGroupNews").selectedIndex].value;
    retValue = Portal.CMS.MoveNews.ServerSideDetectGroupNewsItem(GroupNewsId).value;
    document.getElementById("divSelectGroupNewsItems").innerHTML = retValue;
}


function RunFilterStdAlone() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.InputNews.GetProcessingMsg().value;
    setTimeout("RealRunFilterStdAlone()", 10);
}


function RealRunFilterStdAlone() {
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    GroupNewsItemId = document.getElementById("txtGroupNewsItemId").value;
    GroupNewsId = document.getElementById("txtGroupNewsId").value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.InputNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatusIndex, PageIndex).value;
    if (value.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(value);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divNewsContent").innerHTML = value;
}




function ClientSearchNewsRelation() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.UpdateRelationNews.GetProcessingText().value;
    setTimeout("RealClientSearchNewsRelation()", 10);
}

function RealClientSearchNewsRelation() {
    SrcNewsId = document.getElementById("txtSrcNewsId").value;
    WorkflowStatusIndex = document.getElementById("drpSelectWorkflowStatus").selectedIndex;
    Keyword = document.getElementById("txtSearchKeyword").value;
    fromDate = document.getElementById("txtFromDate").value;
    toDate = document.getElementById("txtToDate").value;
    belongSiteIndex = document.getElementById("drpSelectSiteForSearchNews").selectedIndex;
    belongSite = document.getElementById("drpSelectSiteForSearchNews").options[belongSiteIndex].value;
    GroupNewsItemId = document.getElementById("drpSelectGroupNewsItem").options[document.getElementById("drpSelectGroupNewsItem").selectedIndex].value;
    Source = document.getElementById("txtSource").value;
    PageIndex = 0;
    if (document.getElementById("divSelectSearchNewsPage") != null) {
        PageIndex = document.getElementById("divSelectSearchNewsPage").selectedIndex;
    }

    retValue = Portal.CMS.UpdateRelationNews.SearchRelationNews(SrcNewsId, belongSite, Keyword, fromDate, toDate, WorkflowStatusIndex, GroupNewsItemId, Source, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divSearchNewsContent").innerHTML = retValue;
}


function ClientAddNewsRelation(NewsId) {
    SrcNewsId = document.getElementById("txtSrcNewsId").value;
    retValue = Portal.CMS.UpdateRelationNews.ServerSideAddNewsRelation(SrcNewsId, NewsId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
    }
    else {
        alert("Thiết lập tin liên quan thành công!");
        document.getElementById("divAddNewsRelationItem_" + NewsId).innerHTML = "";
        document.getElementById("divAlreadyNewsRelation").innerHTML = retValue;
    }
}

function ClientRemoveNewsRelation(NewsRelationId) {
    if (confirm("Bạn đã chắc chắn chưa?") == false) return;
    SrcNewsId = document.getElementById("txtSrcNewsId").value;
    retValue = Portal.CMS.UpdateRelationNews.ServerSideRemoveNewsRelation(SrcNewsId, NewsRelationId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
    }
    else {
        alert("Loại bỏ tin liên quan thành công!");
        document.getElementById("divAlreadyNewsRelation").innerHTML = retValue;
    }
}


function ClientShowRelationNewsForm(NewsId) {
    url = Portal.CMS.InputNews.GetRelationFormUrl(NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    window.open(url, '_blank');
}


function ClientShowAttachmentsNewsForm(NewsId) {
    url = Portal.CMS.InputNews.GetAttachmentFormUrl(NewsId).value;
    if (url.indexOf("ERROR") != -1) {
        alert(url);
        return;
    }
    window.open(url, '_blank');
}

function ClientDeleteStdAloneNews(GroupNewsId, GroupNewsItemId, NewsId) {
    value = Portal.CMS.InputNews.CheckAllowDelete(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    if (confirm(Portal.CMS.InputNews.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.InputNews.ServerSideDeleteNews(NewsId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.InputNews.GetDeleteOkMsg().value);
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    PageIndex = 0;
    if (document.getElementById("divSelectPage") != null) {
        PageIndex = document.getElementById("divSelectPage").selectedIndex;
    }
    value = Portal.CMS.InputNews.GetHtml(GroupNewsId, GroupNewsItemId, WorkflowStatus, PageIndex).value;
    document.getElementById("divNewsContent").innerHTML = value;
}


function ClientSaveIndexRelationNews(NewsId) {
    MaxRelationNews = document.getElementById("txtMaxRelationNews").value;
    for (var iIndex = 0; iIndex < MaxRelationNews; iIndex++) {
        SortIndex = document.getElementById("txtIndex" + iIndex).value;
        NewsRelationId = document.getElementById("txtRelationNewsId" + iIndex).value;
        ErrorMsg = Portal.CMS.UpdateRelationNews.ServerSideSaveNewsRelationIndex(NewsId, NewsRelationId, SortIndex).value;
        if (ErrorMsg.indexOf("ERROR") != -1) {
            alert(ErrorMsg);
            return;
        }
     
    }
}


function ClientSaveIndexAttachmentsNews(NewsId) {
    MaxRelationNews = document.getElementById("txtMaxRelationNews").value;
    for (var iIndex = 0; iIndex < MaxRelationNews; iIndex++) {
        SortIndex = document.getElementById("txtIndex" + iIndex).value;
        NewsRelationId = document.getElementById("txtRelationNewsId" + iIndex).value;
        ErrorMsg = Portal.CMS.UpdateAttachmentsNews.ServerSideSaveNewsAttachmentsIndex(NewsRelationId, SortIndex).value;
        if (ErrorMsg.indexOf("ERROR") != -1) {
            alert(ErrorMsg);
            return;
        }
    }
    alert(ErrorMsg);
}


//function ClientResetDocumentContent(belongSite, NewsId) {
//    ErrorMsg = Portal.CMS.InputNews.ServerSideResetDocumentContent(belongSite, NewsId).value;
//    alert(ErrorMsg);
//}

function ClientResetDocumentContent(NewsId, AttachmentId) {
    ErrorMsg = Portal.CMS.UpdateAttachmentsNews.ServerSideResetDocumentContent(NewsId, AttachmentId).value;
    alert(ErrorMsg);
}
